package com.guigu.www.Service.Impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.guigu.www.Service.ClassService;
import com.guigu.www.dao.ClassMapper;
import com.guigu.www.dao.ZyMapper;
import com.guigu.www.pojo.Class;
import com.guigu.www.pojo.PageVo;
import com.guigu.www.pojo.Zy;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

@Service
public class ClassServiceImpl implements ClassService {
    @Autowired
    ClassMapper mapper;
    @Autowired
    ZyMapper zyMapper;
    @Override
    public PageVo<Class> findClassPage(Map<String,String> map) {
        Class aClass = new Class();
        aClass.setCname(map.get("cname"));
        PageHelper.startPage(
                Integer.valueOf(map.get("pageNum")==null?"1":map.get("pageNum"))
                ,Integer.valueOf(map.get("pageSize")==null?"3":map.get("pageSize"))
        );
        List<Class> classPage = mapper.findClassPage(aClass);
        PageInfo<Class> pageInfo = new PageInfo<>(classPage);
        long total = pageInfo.getTotal();
        List<Class> list = pageInfo.getList();
        return new PageVo<Class>(total,list);
    }

    @Override
    public void deleteByPrimaryKey(Integer cid) {
        mapper.deleteByPrimaryKey(cid);
    }

    @Override
    public void insert(Class record) {
        mapper.insert(record);
    }

    @Override
    public Class selectByPrimaryKey(Integer cid) {
        return mapper.selectByPrimaryKey(cid);
    }

    @Override
    public void updateByPrimaryKey(Class record) {
        mapper.updateByPrimaryKey(record);
    }

    @Override
    public List<Zy> findZy() {
        return zyMapper.findZy();
    }
}
